<?php

namespace App\Services\Admin;
use Illuminate\Support\Facades\Log;
use App\Models\Icon;

class IconService extends AdminService{


    /**
     * 获取列表
     * @param [type] $page
     * @param [type] $per_page
     * @param [type] $filter
     * @method getList
     * @author chengzhigang<1256699215@qq.com>
     */
    public function getList($page,$per_page,$filter){
        try{
            $data = Icon::where(function($query) use ($filter){
                $filter && $query->where('name','like','%'.trim($filter).'%')->orWhere('desc','like','%'.trim($filter).'%');
            })->paginate($per_page,['*'],'page',$page)->toArray();
            return ['status'=>1,'msg'=>'请求成功','data'=>$data];
        }catch(\Exception $e){
            Log::info($e->getCode());
            Log::info($e->getFile());
            Log::info($e->getLine());
            Log::info('图标列表：' . $e->getMessage());
            writeErrorLog($e);
            return ['status' => 2, 'msg' => config('const.error'), 'data' => []];
        }
    }
}
